<?php
include 'config.php';

$sql1 = "SELECT buy.*,n.number_name,b.breed_name,t.type_name,g.stock_goods_price FROM buy_goods_log buy left join `number` n on buy.number_id=n.number_id left join breed b on buy.breed_id=b.breed_id left join type t on buy.type_id=t.type_id left join stock_goods_log g on buy.number_id=g.number_id WHERE 1 ORDER BY buy.buy_goods_id DESC LIMIT 0,15";
$rs1 = $mysql->execute($sql1);
$array1 = array();
$n1 = 0;
while($row1 = mysql_fetch_assoc($rs1)){
	$n1 = $n1;
	$num1 = $n1%2;
	$row1['num1'] = $num1;
	$income = ($row1['buy_goods_price']-$row1['stock_goods_price'])*$row1['buy_goods_num'];
	$row1['income'] = $income;
	$array1[] = $row1;
	$n1++;
}
$smarty->assign('arr1', $array1);
//查询今日收入
$day_time = strtotime(date('Y-m-d',time()));
//昨天事件
$temp_time = strtotime("-1 day");
$yestday_time = strtotime(date('Y-m-d',$temp_time));
$temp_time = strtotime("-2 day");
$before_yestday_time = strtotime(date('Y-m-d',$temp_time));
$week_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))));

$smarty->assign('link', 6);
$before_week_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))));
$month_time = strtotime(date("Y-m-d",mktime(0, 0 , 0,date("m"),1,date("Y"))));

$before_month_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))));
//echo date('Y-m-d',$before_month_time);
$sql = "SELECT SUM(  `buy_goods_num` *  `buy_goods_price` ) price FROM  `buy_goods_log` WHERE 1";
$day_sql = $sql." and buy_goods_date>={$day_time}";
$yestday_sql =$sql." and buy_goods_date>={$yestday_time} and buy_goods_date<{$day_time}";
$before_yestday_sql = $sql." and buy_goods_date>={$before_yestday_time} and buy_goods_date<{$yestday_time}";
$week_sql = $sql." and buy_goods_date>={$week_time}";
$before_week_sql = $sql." and buy_goods_date<{$week_time} and buy_goods_date>={$before_week_time}";
$month_sql = $sql." and buy_goods_date>={$month_time}";
$before_month_sql = $sql." and buy_goods_date<{$month_time} and buy_goods_date>=$before_month_time";

$day_rs = $mysql->execute($day_sql);
$day_arr = mysql_fetch_assoc($day_rs);

$yestday_rs = $mysql->execute($yestday_sql);
$yestday_arr = mysql_fetch_assoc($yestday_rs);

$before_yestday_rs = $mysql->execute($before_yestday_sql);
$before_yestday_arr = mysql_fetch_assoc($before_yestday_rs);

$week_rs = $mysql->execute($week_sql);
$week_arr = mysql_fetch_assoc($week_rs);

$before_week_rs = $mysql->execute($before_week_sql);
$before_week_arr = mysql_fetch_assoc($before_week_rs);

$month_rs = $mysql->execute($month_sql);
$month_arr = mysql_fetch_assoc($month_rs);

$before_month_rs = $mysql->execute($before_month_sql);
$before_month_arr = mysql_fetch_assoc($before_month_rs);


$smarty->assign('day_arr',$day_arr);
$smarty->assign('yestday_arr',$yestday_arr);
$smarty->assign('before_yestday_arr',$before_yestday_arr);
$smarty->assign('week_arr',$week_arr);
$smarty->assign('before_week_arr',$before_week_arr);
$smarty->assign('month_arr',$month_arr);
$smarty->assign('before_month_arr',$before_month_arr);

$smarty->assign('day_cha',round(abs($day_arr['price']-$yestday_arr['price']),4)/100);
$smarty->assign('yestday_cha',round(abs($yestday_arr['price']-$before_yestday_arr['price']),4)/100);
$smarty->assign('week_cha',round(abs($week_arr['price']-$before_week_arr['price']),4)/100);
$smarty->assign('month_cha',round(abs($month_arr['price']-$before_month_arr['price']),4)/100);

$time = date("Y-m-d",time());
$smarty->assign('time',$time);

$smarty->display('proceed.html');